<template>
  <div class="delete-wrapper">
    <div class="tool-bar">
      <el-button type="primary" @click="getTaskList">刷新</el-button>
      <el-button type="primary" @click="addTaskList">新增任务</el-button>
      <el-button @click="addDefaultTask">初始化默认任务</el-button>
    </div>
    <el-table v-loading="taskTableLoading" :data="taskData" class="table" border show-overflow-tooltip>
      <el-table-column type="index" width="50" align="center" />
      <el-table-column prop="name" label="名称" width="180" align="center" />
      <el-table-column prop="taskDesc" label="描述" width="150" align="center">
        <template #default="scope">
          <span v-if="!scope.row.taskDesc">-</span>
          <span v-else>{{ scope.row.taskDesc }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="dbName" label="数据库" width="120" align="center" />
      <el-table-column prop="period" label="数据保留期限" width="130" align="center">
        <template #default="scope">
          <span>{{ getPeriodLabel(scope.row.period) }}</span>
        </template>
      </el-table-column>
      <el-table-column prop="cron" label="Cron" width="100" align="center" />
      <el-table-column prop="taskPriority" label="优先级" width="100" align="center" />
      <el-table-column prop="status" label="状态" width="110" align="center">
        <template #default="scope">
          <el-tag v-if="scope.row.status == 1" type="success">启动</el-tag>
          <el-tag v-else type="danger">停止</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="createTime" label="创建时间" align="center" width="160" />
      <el-table-column prop="operate" label="操作" align="center" fixed="right">
        <template #default="scope">
          <!-- 默认任务可以编辑，可以启动，可以停止，不可以删除 -->
          <el-button :disabled="scope.row.status == 1" @click="editDeleteTask(scope.row)">编辑</el-button>
          <el-button
            v-if="scope.row.status == 0 && scope.row.period != 'FOREVER'"
            type="primary"
            @click="taskStart(scope.row.id)"
            >启动</el-button
          >
          <el-button
            v-else-if="scope.row.period != 'FOREVER' && scope.row.status == 1"
            type="danger"
            @click="taskStop(scope.row.id)"
            >停止</el-button
          >
          <el-button v-if="scope.row.status == 0" type="danger" @click="deleteTask(scope.row.id)">删除</el-button>
          <el-button @click="showLog(scope.row.id)">查看日志</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      v-model="taskEditVisiable"
      :title="taskEditDialogTitle"
      width="500"
      :close-on-click-modal="false"
      destroy-on-close
      @closed="taskEditDialogClose"
    >
      <el-form
        v-loading="edirOrAddLoading"
        ref="editFormRef"
        :rules="editFormRules"
        label-position="left"
        label-width="auto"
        :model="editTaskModel"
      >
        <el-form-item label="名称" prop="name">
          <el-input v-model.trim="editTaskModel.name" :disabled="!operateType" :maxlength="64" />
        </el-form-item>
        <el-form-item label="描述" prop="taskDesc">
          <el-input v-model.trim="editTaskModel.taskDesc" :maxlength="128" />
        </el-form-item>
        <el-form-item label="Cron表达式" prop="cron">
          <div style="display: flex; width: 100%">
            <el-input ref="cronInputRef" style="width: 100%" v-model="editTaskModel.cron" />
            <el-button style="margin-left: 12px" icon="Edit" @click="editCronExpress" />
          </div>
        </el-form-item>
        <el-form-item label="数据库" prop="dbName">
          <el-select
            v-model="editTaskModel.dbName"
            placeholder="请选择数据库"
            :disabled="!operateType"
            @change="changeDb"
          >
            <el-option v-for="item in databaseOption" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="测点" prop="tableNames">
          <div style="display: flex; width: 100%">
            <el-input v-model="editTaskModel.tableNames" disabled />
            <!-- 支持上传文件解析测点，要确保数据库中有表格 -->
            <el-upload
              ref="uploadRef"
              v-model:file-list="tagFileList"
              :auto-upload="false"
              :on-exceed="handleExceed"
              :show-file-list="false"
              :limit="1"
              accept=".csv,.xlsx,.xls"
            >
              <el-button style="margin-left: 12px" icon="Upload" :disabled="editTaskModel.defaultTask == 1" />
            </el-upload>
            <!-- 支持选择测点，前提是要选择数据库 -->
            <el-button
              style="margin-left: 12px"
              :disabled="editTaskModel.defaultTask == 1"
              icon="MoreFilled"
              @click="toSelectTag"
            />
          </div>
        </el-form-item>
        <el-form-item label="数据保留期限" prop="period">
          <el-select v-model="editTaskModel.period" placeholder="请选择数据保留期限">
            <el-option v-for="item in periodOption" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
        <el-form-item label="优先级" prop="taskPriority">
          <el-input-number
            v-model="editTaskModel.taskPriority"
            v-if="editTaskModel.defaultTask == 1"
            :min="minValue"
            :max="100000"
            :step="1"
            :disabled="editTaskModel.defaultTask == 1"
          />
          <el-input-number v-model="editTaskModel.taskPriority" v-else :min="1" :max="99999" :precision="0" :step="1" />
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="taskEditVisiable = false" :disabled="edirOrAddLoading">取消</el-button>
          <el-button :disabled="edirOrAddLoading" type="primary" @click="confirmTaskEdit"> 确认 </el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 默认任务初始化弹窗 -->
    <el-dialog
      v-model="defaultTaskVisiable"
      title="初始化默认任务"
      width="500"
      :close-on-click-modal="false"
      destroy-on-close
    >
      <el-form
        ref="defaultFormRef"
        label-position="left"
        :rules="defaultRules"
        label-width="auto"
        :model="defaultTaskModel"
      >
        <el-form-item label="数据库" prop="dbName">
          <el-select v-model="defaultTaskModel.dbName" placeholder="请选择数据库">
            <el-option v-for="item in databaseOption" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="defaultTaskVisiable = false">取消</el-button>
          <el-button type="primary" @click="initDefaultTaskConfirm"> 确认 </el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 选择Cron表达式 -->
    <el-dialog v-model="cronEditVisiable" title="Cron表达式" width="880" :close-on-click-modal="false" destroy-on-close>
      <CronExpress v-model:cronExpress="cronExpressTemp" :visiable="cronEditVisiable"> </CronExpress>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="cronEditVisiable = false">取消</el-button>
          <el-button type="primary" @click="cronConfirm"> 确认 </el-button>
        </div>
      </template>
    </el-dialog>
    <!-- 选择测点相关内容 -->
    <el-dialog
      v-model="selectTagVisiable"
      title="选择测点"
      width="1500"
      style="height: 70%"
      body-class="dialog-body"
      :close-on-click-modal="false"
      destroy-on-close
      @closed="clearSelectedTag"
    >
      <div style="height: 100%; display: flex">
        <div style="width: 50%">
          <TableDialog
            ref="tableSelectRef"
            :dbName="editTaskModel.dbName"
						:databaseInfo="props.databaseInfo"
						:dbInfo="props.dbInfo"
            :dialogWidth="724"
            type="select"
            :visiable="selectTagVisiable"
          >
          </TableDialog>
        </div>
        <div class="divider-icon" @click="transferSelection">
          <el-icon :size="20">
            <DArrowRight />
          </el-icon>
        </div>
        <div style="width: 724px">
          <el-form :inline="true">
            <el-form-item label="名称">
              <el-input size="small" placeholder="请输入名称" v-model.trim="searchSelectedTagWord" clearable />
            </el-form-item>
            <el-form-item label="描述">
              <el-input size="small" placeholder="请输入描述" v-model.trim="searchSelectedTagDesc" clearable />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" class="el-icon-search" size="small" @click="updateViewSelectedTag">
                查询
              </el-button>
              <el-button type="danger" class="el-icon-search" size="small" @click="deleteSelectedTag"> 删除 </el-button>
            </el-form-item>
          </el-form>
          <el-table
            ref="selectedTableRef"
            :data="viewSelectedTag"
            stripe
            border
            show-overflow-tooltip
            style="height: calc(100% - 90px)"
          >
            <el-table-column type="selection" width="40"> </el-table-column>
            <el-table-column prop="table_name" label="名称" width="180" align="center" />
            <el-table-column prop="desc" label="描述" align="center" />
            <el-table-column prop="valueType" label="测点类型" align="center">
              <template #default="scope">
                <el-tag v-if="scope.row.valueType" type="primary">{{ scope.row.valueType }}</el-tag>
                <el-tag v-else type="primary"> - </el-tag>
              </template>
            </el-table-column>
          </el-table>
          <el-pagination style="margin-top: 12px; float: right" layout="total" :total="viewSelectedTag.length" />
        </div>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="selectTagVisiable = false">取消</el-button>
          <el-button type="primary" @click="tableNamesConfirm"> 确认 </el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 查看日志 -->
    <el-drawer v-model="logDrawerVisiable" title="任务日志" direction="rtl" size="900">
      <el-table :data="logData" style="width: 100%; height: 100%" show-overflow-tooltip border>
        <el-table-column type="index" width="50" align="center" />
        <el-table-column prop="startTime" label="开始时间" width="180" align="center" />
        <el-table-column prop="endTime" label="结束时间" width="180" align="center">
          <template #default="scope">
            <span v-if="scope.row.endTime">{{ scope.row.endTime }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
        <el-table-column prop="status" label="状态" align="center" width="120">
          <template #default="scope">
            <el-tag v-if="scope.row.status == 1" type="success">启动</el-tag>
            <el-tag v-else type="danger">停止</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="period" label="数据保留期限" align="center" width="120">
          <template #default="scope">
            <span>{{ getPeriodLabel(scope.row.period) }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="taskLog" label="任务日志">
          <template #default="scope">
            <span v-if="scope.row.taskLog">{{ scope.row.taskLog }}</span>
            <span v-else>-</span>
          </template>
        </el-table-column>
      </el-table>
    </el-drawer>
  </div>
</template>
<script lang="js" setup>
import { ref, reactive, onMounted, computed, nextTick, watch, defineProps } from 'vue';
import { list, initDefaultTask, saveOrUpdate, deleteById, start, stop, listDeleteLog } from "@/api/delete"
import { ElMessage, genFileId, ElMessageBox } from 'element-plus';
import CronExpress from '@/components/CronExpress.vue'
import TableDialog from '@/views/tagManage/TableDialog.vue'
import * as cronParse from "cron-parser";
const minValue = ref(-1);
//任务信息
const taskData = ref([])
//属性值
const props = defineProps({
	dbInfo:{
		type:Object,
		default:{},
	},
	databaseInfo:{
		type:Array,
		default:[]
	}
})
//连接信息
const store = {
	info:props.dbInfo,
	databaseInfo:props.databaseInfo
}
const taskTableLoading = ref(false);
//获取任务列表
const getTaskList = () => {
	let data = {
		host: store.info.host,
		port: store.info.port,
	}
	taskTableLoading.value = true;
	list(data).then(res => {
		if (res.code == 200) {
			taskData.value = res.data;
		} else {
			ElMessage.error(res.msg);
		}
		taskTableLoading.value = false;
	}).catch(e=>{
		console.error(e);
		taskTableLoading.value = false;
	})
}
const updateDatabase = ()=>{
	  databaseOption.length = 0;
		props.databaseInfo.forEach(item => {
			databaseOption.push({
				label: item,
				value: item
			})
		})
}
const databaseOption = reactive([]);
onMounted(() => {
	getTaskList();
	//更新数据库信息
	updateDatabase();
})

//默认任务相关
const defaultTaskVisiable = ref(false);
const defaultTaskModel = ref({
	dbName: '',
	host: store.info.host,
	port: store.info.port,
	username: store.info.username,
	password: store.info.password
})
const addDefaultTask = () => {
	updateDatabase();
	defaultTaskVisiable.value = true;
}
const defaultRules = {
	dbName: [
		{ required: true, message: '请选择数据库', trigger: ['blur', 'change'] },
	]
}
//初始化默认任务确认
const defaultFormRef = ref(null);
const initDefaultTaskConfirm = () => {
	if (defaultFormRef) {
		defaultFormRef.value.validate(valid => {
			if (valid) {
				defaultTaskVisiable.value = false;
				initDefaultTask(defaultTaskModel.value).then(res => {
					if (res.code == 200) {
						getTaskList();
					} else {
						ElMessage.error(res.msg);
					}
					defaultTaskModel.value.dbName = ''
				})
			}
		})
	}
}

const periodOption = [
	{ label: '一个月', value: "ONE_MONTH" },
	{ label: '三个月', value: "THREE_MONTH" },
	{ label: '六个月', value: "SIX_MONTH" },
	{ label: '一年', value: "ONE_YEAR" },
	{ label: '两年', value: "TWO_YEAR" },
	{ label: '三年', value: "THREE_YEAR" },
	{ label: '五年', value: "FIVE_YEAR" },
	{ label: '永久', value: "FOREVER" }
]
/**
 * 获取清理区间 label
 * @param value 值
 */
const getPeriodLabel = (value) => {
	let label = '';
	for (let i = 0; i < periodOption.length; i++) {
		if (periodOption[i].value == value) {
			label = periodOption[i].label;
			break;
		}
	}
	return label;
}

//新增、编辑删除任务,香瓜内容
const taskEditVisiable = ref(false);
const edirOrAddLoading = ref(false);
//true 新增 false 删除
const operateType = ref(true)
const taskEditDialogTitle = computed(() => {
	if (operateType.value) {
		return '新增'
	} else {
		return '编辑'
	}
})
const addTaskList = () => {
	updateDatabase();
	//新增
	operateType.value = true;
	taskEditVisiable.value = true;
}
const editDeleteTask = (rowData) => {
	let tableNamesTemp = null;
	if (rowData.tableNames) {
		tableNamesTemp = rowData.tableNames.split(",");
	}
	if (rowData.tableNames && tableNamesTemp.length > 6000) {
		ElMessage.warning("选择测点数量为：" + tableNamesTemp.length + ",数量过大，不允许编辑！");
		return;
	}
	//赋值
	editTaskModel.value.id = rowData.id;
	editTaskModel.value.name = rowData.name;
	editTaskModel.value.taskDesc = rowData.taskDesc;
	editTaskModel.value.cron = rowData.cron;
	editTaskModel.value.taskPriority = rowData.taskPriority;
	editTaskModel.value.defaultTask = rowData.defaultTask;
	if (rowData.defaultTask != 1) {
		editTaskModel.value.tableNames = tableNamesTemp;
	}
	editTaskModel.value.period = rowData.period;
	editTaskModel.value.dbName = rowData.dbName;
	//编辑
	lastTagUploadType.value = 'select';
	operateType.value = false;
	taskEditVisiable.value = true;
}

const editTaskModel = ref({
	name: '',
	taskDesc: '',
	cron: '',
	taskPriority: 1,
	tableNames: [],
	period: '',
	dbName: '',
})
/**
 * 选择cron表达式相关内容
 */
const cronExpressTemp = ref('')
const editCronExpress = () => {
	cronEditVisiable.value = true;
	cronExpressTemp.value = editTaskModel.value.cron;
}
const cronEditVisiable = ref(false);
//时间格式化
const dateFormat = (obj) => {
	let time = obj._date.c;
	return (
		time.year +
		"-" +
		time.month.toString().padStart(2, "0") +
		"-" +
		time.day.toString().padStart(2, "0") +
		" " +
		time.hour.toString().padStart(2, "0") +
		":" +
		time.minute.toString().padStart(2, "0") +
		":" +
		time.second.toString().padStart(2, "0")
	);
};
const cronInputRef = ref(null);
const cronConfirm = () => {
	let value = cronExpressTemp.value;
	let val = cronParse.parseExpression(value);
	let diffValue = Number.MAX_SAFE_INTEGER;
	let prevTime = 0;
	for (let i = 0; i < 60; i++) {
		let value = new Date(dateFormat(val.next())).getTime();
		if (prevTime == 0) {
			prevTime = value;
		} else {
			if ((value - prevTime) < diffValue) {
				diffValue = value - prevTime;
			}
		}
	}
	if (diffValue / 1000 < 86400) {
		ElMessage.warning("任务间隔时间需大于一天")
	} else {
		cronEditVisiable.value = false;
		nextTick(() => {
			editTaskModel.value.cron = cronExpressTemp.value;
			cronInputRef.value.blur();
		})
	}
}

/**
 * 选择测点相关内容
 */
const selectTagVisiable = ref(false);
const toSelectTag = () => {
	if (!editTaskModel.value.dbName) {
		ElMessage.warning("请选择数据库");
		return;
	}
	selectedTag.value.length = 0
	editTaskModel.value.tableNames.forEach(item => {
		selectedTag.value.push({
			table_name: item,
			desc: '-',
			valueType: ''
		})
	})
	updateViewSelectedTag();
	selectTagVisiable.value = true;
}
//所有数据
const searchSelectedTagDesc = ref("");
const searchSelectedTagWord = ref("");
const selectedTag = ref([])
const viewSelectedTag = ref([])
//用于展示过滤的最后显示结果
const updateViewSelectedTag = () => {
	let data = selectedTag.value;
	if (searchSelectedTagDesc.value) {
		data = data.filter(item => item.desc.indexOf(searchSelectedTagDesc.value) > -1);
	}
	if (searchSelectedTagWord.value) {
		data = data.filter(item => item.table_name.indexOf(searchSelectedTagWord.value) > -1);
	}
	viewSelectedTag.value = data;
}

//将选中的内容移动到选中表格
const tableSelectRef = ref(null);
const transferSelection = () => {
	//当前选择的测点
	let data = tableSelectRef.value.getTableSelection();
	//可能会有重复的，需要把重复的剔除
	data.forEach(item => {
		if (selectedTag.value.findIndex(i => i.table_name == item.table_name) == -1) {
			selectedTag.value.push(item);
		}
	})
	updateViewSelectedTag();
}
//已经被选中的表格
const selectedTableRef = ref(null);
//删除选中的测点
const deleteSelectedTag = () => {
	let selections = selectedTableRef.value.getSelectionRows();
	for (let i = 0; i < selections.length; i++) {
		let item = selections[i];
		let targetIndex = selectedTag.value.findIndex(i => i.table_name == item.table_name);
		if (targetIndex > -1) {
			selectedTag.value.splice(targetIndex, 1);
		}
	}
	updateViewSelectedTag();
}
//清空选择的测点
const clearSelectedTag = () => {
	searchSelectedTagWord.value = '';
	searchSelectedTagDesc.value = '';
	updateViewSelectedTag();
}
//测点上传的方式 file 文件上传 select 选择文本
const lastTagUploadType = ref('file')
const tagFileList = ref([]);
watch(
	() => tagFileList.value,
	() => {
		if (tagFileList.value && tagFileList.value[0]) {
			editTaskModel.value.tableNames = [tagFileList.value[0].name];
			lastTagUploadType.value = 'file';
		}
	}
);
const uploadRef = ref(null);
//手动设置选择最新的文件
const handleExceed = (files) => {
	uploadRef.value.clearFiles();
	const file = files[0];
	file.uid = genFileId();
	uploadRef.value.handleStart(file);
}
const tableNamesConfirm = () => {
	let data = selectedTag.value;
	if(data.length == 0){
		ElMessage.warning("请选择测点")
		return ;
	}
	//如果手动选择，则清空文件
	if (uploadRef.value) {
		uploadRef.value.clearFiles();
	}
	editTaskModel.value.tableNames = data.map(item => item.table_name);
	selectTagVisiable.value = false;
	lastTagUploadType.value = 'select';
}
const cronCheck = (rules, value, callback) => {
	try {
		let val = cronParse.parseExpression(value);
		callback();
	} catch (e) {
		callback(new Error("请输入正确的Cron表达式"));
	}
}
const priorityCheck = (rules, value, callback) => {
	let targetIndex = taskData.value.findIndex(item => {
		if(item.taskPriority == value && item.defaultTask != 1 && item.id != editTaskModel.value.id){
			if(editTaskModel.value.dbName){
				if(editTaskModel.value.dbName == item.dbName){
					return true;
				}else{
					return false;
				}
			}else{
				return true;
			}
		}else{
			return false;
		}
	});
	if (targetIndex > -1) {
		callback(new Error("当前优先级存在任务"));
	} else {
		callback();
	}
}
const nameCheck = (rules, value, callback) => {
	if (editTaskModel.value.defaultTask == 1) {
		callback();
	} else {
		let targetIndex = taskData.value.findIndex(item => item.name == value && item.id != editTaskModel.value.id);
		if (targetIndex > -1) {
			callback(new Error("名称重复"));
		} else {
			callback();
		}
	}
}
const tableNameCheck = (rules, value, callback) => {
	if ((!value || value.length == 0) && editTaskModel.value.defaultTask != 1) {
		callback(new Error("请选择测点"));
	} else {
		callback();
	}

}
//表单验证
const editFormRules = {
	name: [
		{ required: true, message: '请输入名称', trigger: 'blur' },
		{ validator: nameCheck, trigger: ['blur', 'change'] }
	],
	cron: [
		{ required: true, message: '请输入Cron表达式', trigger: ['blur', 'change'] },
		{ validator: cronCheck, trigger: ['blur', 'change'] }
	],
	tableNames: [
		{ required: true, validator: tableNameCheck, trigger: ['blur', 'change'] }
	],
	dbName: [
		{ required: true, message: '请选择数据库', trigger: ['blur', 'change'] }
	],
	period: [
		{ required: true, message: '请选择数据保留期限', trigger: ['blur', 'change'] }
	],
	taskPriority: [
		{ required: true, message: '请输入任务优先级', trigger: 'blur' },
		{ validator: priorityCheck, trigger: ['blur', 'change'] }
	],
}
//关闭弹窗重置
const taskEditDialogClose = () => {
	editTaskModel.value = {
		name: '',
		taskDesc: '',
		cron: '',
		taskPriority: 1,
		tableNames: [],
		period: '',
		dbName: '',
	}
}
const editFormRef = ref(null);
const confirmTaskEdit = () => {
	editFormRef.value.validate((valid) => {
		if (valid) {
			edirOrAddLoading.value = true;
			const data = new FormData();
			data.append("id", editTaskModel.value.id ? editTaskModel.value.id : '')
			data.append("name", editTaskModel.value.name)
			data.append("taskDesc", editTaskModel.value.taskDesc)
			data.append("cron", editTaskModel.value.cron)
			data.append("taskPriority", editTaskModel.value.taskPriority)
			data.append("period", editTaskModel.value.period)
			data.append("dbName", editTaskModel.value.dbName)
			data.append("host", store.info.host)
			data.append("port", store.info.port)
			data.append("username", store.info.username)
			data.append("password", store.info.password)
			data.append("defaultTask", editTaskModel.value.defaultTask ? editTaskModel.value.defaultTask : 0)
			if (editTaskModel.value.defaultTask != 1) {
				if (lastTagUploadType.value == 'select') {
					data.append("tableNames", editTaskModel.value.tableNames.join(','))
				} else {
					data.append("multipartFile", tagFileList.value[0].raw)
				}
			}
			saveOrUpdate(data).then(res => {
				if (res.code == 200 && res.data) {
					getTaskList();
					taskEditVisiable.value = false;
				} else {
					ElMessage.error(res.msg);
				}
				edirOrAddLoading.value = false;
			}).catch(() => {
				edirOrAddLoading.value = false;
			})
		}
	})
}

const deleteTask = (id) => {
	ElMessageBox.confirm(
		'删除任务同时会删除任务日志，确认删除任务?',
		'提示',
		{
			confirmButtonText: '确认',
			cancelButtonText: '取消',
			type: 'warning',
		}
	)
		.then(() => {
			let data = {
				id: id
			}
			deleteById(data).then(res => {
				if (res.code == 200 && res.data) {
					getTaskList();
				} else {
					ElMessage.error(res.msg);
				}
			})
		});
}

const taskStop = (id) => {
	let data = {
		id: id
	}
	stop(data).then(res => {
		if (res.code == 200 && res.data) {
			getTaskList();
		} else {
			ElMessage.error(res.msg);
		}
	})
}

const taskStart = (id) => {
	let data = {
		id: id
	}
	start(data).then(res => {
		if (res.code == 200 && res.data) {
			getTaskList();
		} else {
			ElMessage.error(res.msg);
		}
	})
}
//查看日志相关
const logDrawerVisiable = ref(false);
const logData = ref([])
const showLog = (id) => {
	logDrawerVisiable.value = true;
	let data = {
		taskId: id
	}
	listDeleteLog(data).then(res => {
		if (res.code == 200 && res.data) {
			logData.value = res.data;
		} else {
			logData.value.length = 0;
			ElMessage.error(res.msg);
		}
	})
}

const changeDb = () => {
	if (editTaskModel.value.defaultTask != 1) {
		if (lastTagUploadType.value == 'select') {
			editTaskModel.value.tableNames.length = 0;
		}
	}
}
</script>
<style lang="less">
.dialog-body {
  height: calc(100% - 90px);

  .divider-icon {
    height: 100%;
    display: flex;
    align-items: center;
    width: 56px;
    justify-content: center;
    cursor: pointer;
  }
}
</style>
<style lang="less" scoped>
.delete-wrapper {
  padding: 16px;
  width: 100%;
  height: 100%;

  :deep(.el-drawer__header) {
    margin-bottom: 0;
  }

  .tool-bar {
    width: 100%;
    height: 48px;
    display: flex;
    align-items: center;
  }

  .table {
    width: 100%;
    height: calc(100% - 48px);
  }
}
</style>
